import 'package:flutter/material.dart';

import 'Home.dart';
import 'Cate.dart';
import 'Setting.dart';
import 'AppBar.dart';

class Tabs extends StatefulWidget {  
  
  Tabs({Key key}) : super(key: key);

  @override
  _TabsState createState() => _TabsState();
}

class _TabsState extends State<Tabs> {
  int _currentIndex = 0;
  
  List _pageList = <Widget> [
    HomePage(),
    CatePage(),
    SettingPage(),
    AppBarPage()
  ];
  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('FlutterDemo')), 
      
      floatingActionButton: Container(
        height: 45,
        width: 45,
        padding: EdgeInsets.all(4),
        margin: EdgeInsets.only(
          top: 20
        ),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(22.5),
          color: Colors.green
        ),
        child: FloatingActionButton(
          child: Icon(Icons.add, color: Colors.white,),
          onPressed: () {
            print("浮动按钮");
            setState(() {
              this._currentIndex = 1;
            });
          },
          backgroundColor: this._currentIndex == 1 ? Colors.blue : Colors.grey,
        )
      ),
      
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,

      body: this._pageList[this._currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: this._currentIndex,
        onTap: (int index) {
          // print(index);
          setState(() {
            this._currentIndex = index;
          });
        },
        selectedItemColor: Colors.blue,
        unselectedItemColor: Colors.grey,
        selectedFontSize: 12.0,
        unselectedFontSize: 12.0,
        type: BottomNavigationBarType.fixed,
        items: [
          BottomNavigationBarItem(
            icon: Icon(Icons.home),
            title: Text("首页")
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.category),
            title: Text("分类")
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.settings),
            title: Text("设置")
          ),
          // BottomNavigationBarItem(
          //   icon: Icon(Icons.ac_unit),
          //   title: Text("导航栏")
          // ),
        ]
      ),
      drawer: Drawer(
        child: Column(
          children: <Widget>[
            Row(
              children: <Widget>[
                Expanded(
                  // child: DrawerHeader(
                  //   child: Text("你好抽屜啊"),
                  //   decoration: BoxDecoration(
                  //     color: Colors.yellow
                  //   ),
                  // )
                  child: UserAccountsDrawerHeader(
                    accountName: Text("陈峰峰呀"),
                    accountEmail: Text("741883227@qq.com"),
                    currentAccountPicture: CircleAvatar(
                      backgroundImage: NetworkImage("https://img2.woyaogexing.com/2020/09/18/e32a95767c55494eb6cef7616caac418!400x400.jpeg"),
                    ),
                    decoration: BoxDecoration(
                      color: Colors.deepOrangeAccent
                    ),
                  ),
                )
              ],
            ),
            ListTile(
              leading: CircleAvatar(
                child: Icon(Icons.home),
              ),
              title: Text("我的空間"),
            ),
            Divider(),
            ListTile(
              leading: CircleAvatar(
                child: Icon(Icons.home),
              ),
              title: Text("個人中心"),
            ),
            Divider(),
            ListTile(
              leading: CircleAvatar(
                child: Icon(Icons.home),
              ),
              title: Text("收藏"),
            ),
            Divider(),
            ListTile(
              leading: CircleAvatar(
                child: Icon(Icons.home),
              ),
              title: Text("開發者中心"),
            )
          ],
        )
      ),
      endDrawer: Drawer(
        child: Text("你好右側抽屉"),
      ),
    );
  }
}